#ifndef MIRROR_ALGORITHM_H
#define MIRROR_ALGORITHM_H

#include "submodule_types.h"
#include <vector>

namespace usm {

class MirrorSelectionAlgorithm {
public:
    MirrorSelectionAlgorithm() = default;
    
    // 镜像发现算法
    std::vector<std::string> discoverMirrorCandidates(const SubmoduleInfo& submodule, 
                                                     const std::vector<MirrorProvider>& providers);
    
    // 评分算法
    int calculateFreshnessScore(const std::string& mirror_url, const std::string& expected_hash);
    int calculatePopularityScore(int reference_count);
    int calculateProviderPriorityScore(const MirrorProvider& provider);
    int calculateNamingSimilarityScore(const std::string& original_name, const std::string& mirror_name);
    
    // 综合评估
    MirrorEvaluation evaluateMirror(const std::string& mirror_url, 
                                   const MirrorProvider& provider,
                                   const SubmoduleInfo& submodule);
    
    // 最优选择
    MirrorEvaluation selectOptimalMirror(const std::vector<MirrorEvaluation>& evaluations);
    
    // 回退策略
    std::vector<MirrorEvaluation> getFallbackOptions(const std::vector<MirrorEvaluation>& evaluations);

private:
    // 算法权重配置
    struct AlgorithmWeights {
        int freshness_weight = 30;
        int popularity_weight = 25;
        int provider_priority_weight = 20;
        int naming_similarity_weight = 15;
        int existence_weight = 10;
    };
    
    AlgorithmWeights weights_;
    
    std::string normalizeRepoName(const std::string& repo_name);
    std::vector<std::string> generateNameVariants(const std::string& repo_name);
};

} // namespace usm
#endif
